
#include <iostream>
#include <pthread.h>
#include <unistd.h>

__thread int cnt=1;//线程局部存储


void* routine1(void *arg)
{
    (void)arg;

    while(1)
    {
        cnt++;
        std::cout<<" routine1 cnt= "<<cnt<<" addr: "<<&cnt<<std::endl;
        sleep(1);
    }
}

void* routine2(void* arg)
{
    (void)arg;

    while(1)
    {
        std::cout<<" routine2 cnt= "<<cnt<<" addr: "<<&cnt<<std::endl;
        sleep(1);
    }
}


int main()
{
    pthread_t tid1;
    pthread_t tid2;

    pthread_create(&tid1,nullptr,routine1,nullptr);
    pthread_create(&tid2,nullptr,routine2,nullptr);

    pthread_join(tid1,nullptr);
    pthread_join(tid2,nullptr);

    return 0;
}